use dotenv as env;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct WeChatProperties {
    pub appid: String,                     // 小程序的appid
    pub secret: String,                    // 小程序的秘钥
    pub mchid: String,                     // 商户号
    pub mch_serial_no: String,             // 商户API证书的证书序列号
    pub private_key_file_path: String,     // 商户私钥文件
    pub api_v3_key: String,                // 证书解密的密钥
    pub wechat_pay_cert_file_path: String, // 平台证书
    pub notify_url: String,                // 支付成功的回调地址
    pub refund_notify_url: String,         // 退款成功的回调地址
}

impl WeChatProperties {
    pub fn load() -> Self {
        Self {
            appid: env::var("wechat.appid").expect("WECHAT_APPID must be set"),
            secret: env::var("wechat.secret").expect("WECHAT_SECRET must be set"),
            mchid: env::var("wechat.mchid").expect("WECHAT_MCHID must be set"),
            mch_serial_no: env::var("wechat.mchSerialNo")
                .expect("WECHAT_MCH_SERIAL_NO must be set"),
            private_key_file_path: env::var("wechat.privateKeyFilePath")
                .expect("WECHAT_PRIVATE_KEY_FILE_PATH must be set"),
            api_v3_key: env::var("wechat.apiV3Key").expect("WECHAT_API_V3_KEY must be set"),
            wechat_pay_cert_file_path: env::var("wechat.weChatPayCertFilePath")
                .expect("WECHAT_PAY_CERT_FILE_PATH must be set"),
            notify_url: env::var("wechat.notifyUrl").expect("WECHAT_NOTIFY_URL must be set"),
            refund_notify_url: env::var("wechat.refundNotifyUrl")
                .expect("WECHAT_REFUND_NOTIFY_URL must be set"),
        }
    }
}
